﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DatabaseHelper;

namespace UI.Online.SubForms
{
    public partial class frmRecords : Form
    {
        public PPipeline CurrentPipeline;
        public int PipelineId;

        public frmRecords()
        {
            InitializeComponent();
            lvRecordList.Columns.Add("Time Start", 150, HorizontalAlignment.Left);
            lvRecordList.Columns.Add("Time End", 150, HorizontalAlignment.Left);
            lvRecordList.Columns.Add("KP Start", 150, HorizontalAlignment.Left);
            lvRecordList.Columns.Add("KP End", 150, HorizontalAlignment.Left);
        }

        public frmRecords(PPipeline pipeline)
            :this()
        {
            CurrentPipeline = pipeline;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmRecords_Load(object sender, EventArgs e)
        {
            txtPipelineName.Text = CurrentPipeline.PipelineName;
            CommonUseMethods cum = new CommonUseMethods();
            PipelineId = cum.FindPipelineId(CurrentPipeline.PipelineName);
            cum.LoadRecordList(ref lvRecordList, PipelineId);
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            DBHelper dh = new DBHelper();
            foreach (ListViewItem Item in lvRecordList.SelectedItems)
            {
                string str = Item.SubItems[0].Text;
                dh.Query = "DELETE * FROM Pipelines WHERE PipelineName = '" + str + "'";
                dh.Execute();
                lvRecordList.Items.Remove(Item);
            }
        }
    }
}
